home *** CD-ROM | disk | FTP | other *** search
/ BMUG Revelations / BMUG Revelations.toast / Utilities / Random / Commodore 64c / SOURCE / AppleEvents.c < prev    next >
Text File  |  1994-03-19  |  5KB  |  212 lines

  1. /*
  2.     Commodore 64 Emulator v0.2      Earle F. Philhower III 
  3.     Copyright (C) 1993-4            (st916w9r@dunx1.ocs.drexel.edu)
  4.  
  5.     This program is free software; you can redistribute it and/or modify
  6.     it under the terms of the GNU General Public License as published by
  7.     the Free Software Foundation; either version 2 of the License, or
  8.     (at your option) any later version.
  9.  
  10.     This program is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.     GNU General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU General Public License
  16.     along with this program; if not, write to the Free Software
  17.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19. #include <AppleEvents.h>
  20. #include <Balloons.h>
  21. #include "ProcessorTypes.h"
  22. #include "Error.h"
  23. #include "FileTypes.h"
  24.  
  25. /* AEVT Routines */
  26. OSErr DoQUIT();
  27. pascal OSErr AEHandleQUIT(const AppleEvent *theAE,const AppleEvent *theRp, long RC);
  28. OSErr DoOAPP();
  29. pascal OSErr AEHandleOAPP(const AppleEvent *theAE,const AppleEvent *theRp, long RC);
  30. OSErr DoODOC(const AppleEvent *theAE,const AppleEvent *theRp);
  31. pascal OSErr AEHandleODOC(const AppleEvent *theAE,const AppleEvent *theRp, long RC);
  32. OSErr DoPDOC(const AppleEvent *theAE,const AppleEvent *theRp);
  33. pascal OSErr AEHandlePDOC(const AppleEvent *theAE,const AppleEvent *theRp, long RC);
  34. byte InstallAppleEventHandlers();
  35.  
  36. DescType missedTypeCode;
  37. long missedActualSize;
  38. #define InstallFinder(z,y) AEInstallEventHandler(kCoreEventClass, z, y, 0, false)
  39. #define InstallCore(z,y) AEInstallEventHandler(kAECoreSuite, z, y, 0, false)
  40. #define MissedParams(z) \
  41.     (AESizeOfAttribute(z, keyMissedKeywordAttr, \
  42.         &missedTypeCode, &missedActualSize) != errAEDescNotFound)
  43.  
  44.  
  45. OSErr DoQUIT()
  46. {
  47.     CleanUpCommodore();
  48.     ExitToShell();
  49. }
  50.  
  51. pascal OSErr AEHandleQUIT(theAppleEvent, theReply, theRefCon)
  52. const AppleEvent *theAppleEvent, *theReply;
  53. long theRefCon;
  54. {
  55.     OSErr err=noErr;
  56.     DescType typeCode;
  57.     long actualSize;
  58.  
  59.     err = DoQUIT();
  60.     if (MissedParams(theAppleEvent) && err==noErr) err = errAEParamMissed;
  61.     /* There should be NO parameters sent to us..if there are, someone's
  62.         got a REAL problem! (not us, though!) */
  63.     
  64.     return(err);
  65. }
  66.  
  67. OSErr DoOAPP()
  68. {
  69. }
  70.  
  71. pascal OSErr AEHandleOAPP(theAppleEvent, theReply, theRefCon)
  72. const AppleEvent *theAppleEvent, *theReply;
  73. long theRefCon;
  74. {
  75.     OSErr err=noErr;
  76.     DescType typeCode;
  77.     long actualSize;
  78.     
  79.     err = DoOAPP();
  80.     if (MissedParams(theAppleEvent) && err==noErr) err = errAEParamMissed;
  81.     
  82.     return(err);
  83. }
  84.  
  85. void OpenFSSpec(FSSpec *spec)
  86. {
  87.     FInfo finfo;
  88.     
  89.     FSpGetFInfo(spec, &finfo);
  90.     switch(finfo.fdType)
  91.     {
  92.     case DISKFTYPE:
  93.         AttachFloppyImage(spec);
  94.         break;
  95.     case RAMFTYPE:
  96.         LoadRAMFS(spec);
  97.         break;
  98.     case PRINTERFTYPE:
  99.         break;
  100.     case TAPEFTYPE:
  101.         LoadTapeFS(spec);
  102.         break;
  103.     }
  104. }
  105.  
  106. OSErr DoODOC(theAppleEvent, theReply)
  107. const AppleEvent *theAppleEvent, *theReply;
  108. {
  109.     OSErr err;
  110.     FSSpec myFSS;
  111.     AEDescList *docList;
  112.     long items;
  113.     long index;
  114.     AEKeyword keywd;
  115.     DescType typeCode;
  116.     Size actualSize;
  117.  
  118.     err = AEGetParamDesc(theAppleEvent, keyDirectObject, typeAEList, docList);
  119.     if (err!=noErr) return (err);
  120.     
  121.     err = AECountItems(docList, &items);
  122.     if (err!=noErr) return (err);
  123.     
  124.     for (index=1; index<=items; index++) {
  125.         err = AEGetNthPtr(docList, index, typeFSS, &keywd, &typeCode, (Ptr)&myFSS,
  126.                     sizeof(myFSS), &actualSize );
  127.         if (err!=noErr) {AEDisposeDesc(docList); return (err);}
  128.         OpenFSSpec(&myFSS);
  129. /*        p2cstr(myFSS.name);*/
  130. /*        printf("ODOC %s\n", myFSS.name);*/}
  131.  
  132.     err = AEDisposeDesc(docList);
  133.     
  134.     return(err);
  135. }
  136.  
  137.  
  138.  
  139. pascal OSErr AEHandleODOC(theAppleEvent, theReply, theRefCon)
  140. const AppleEvent *theAppleEvent, *theReply;
  141. long theRefCon;
  142. {
  143.     OSErr err=noErr;
  144.     DescType typeCode;
  145.     long actualSize;
  146.     
  147.     err = DoODOC(theAppleEvent, theReply);
  148.     if (MissedParams(theAppleEvent) && err==noErr) err = errAEParamMissed;
  149.     
  150.     return(err);
  151. }
  152.  
  153. OSErr DoPDOC(theAppleEvent, theReply)
  154. const AppleEvent *theAppleEvent, *theReply;
  155. {
  156.     OSErr err;
  157.     FSSpec myFSS;
  158.     AEDescList *docList;
  159.     long items;
  160.     long index;
  161.     AEKeyword keywd;
  162.     DescType typeCode;
  163.     Size actualSize;
  164.  
  165.     err = AEGetParamDesc(theAppleEvent, keyDirectObject, typeAEList, docList);
  166.     if (err!=noErr) return (err);
  167.     
  168.     err = AECountItems(docList, &items);
  169.     if (err!=noErr) return (err);
  170.     
  171.     for (index=1; index<=items; index++) {
  172.         err = AEGetNthPtr(docList, index, typeFSS, &keywd, &typeCode, (Ptr)&myFSS,
  173.                     sizeof(myFSS), &actualSize );
  174.         if (err!=noErr) {AEDisposeDesc(docList); return (err);}
  175. /*        p2cstr(myFSS.name);*/
  176.         /*printf("PDOC %s\n", myFSS.name)*/;}
  177.  
  178.     err = AEDisposeDesc(docList);
  179.     
  180.     return(err);
  181. }
  182.  
  183.  
  184.  
  185. pascal OSErr AEHandlePDOC(theAppleEvent, theReply, theRefCon)
  186. const AppleEvent *theAppleEvent, *theReply;
  187. long theRefCon;
  188. {
  189.     OSErr err=noErr;
  190.     DescType typeCode;
  191.     long actualSize;
  192.     
  193.     err = DoPDOC(theAppleEvent, theReply);
  194.     if (MissedParams(theAppleEvent) && err==noErr) err = errAEParamMissed;
  195.     
  196.     return(err);
  197. }
  198.  
  199.     
  200.  
  201. byte InstallAppleEventHandlers()
  202. {
  203.     short err;
  204.     
  205.     if ((err=InstallFinder(kAEQuitApplication, AEHandleQUIT))!=0) return -1;
  206.     if ((err=InstallFinder(kAEOpenApplication, AEHandleOAPP))!=0) return -1;
  207.     if ((err=InstallFinder(kAEOpenDocuments, AEHandleODOC))!=0) return -1;
  208.     if ((err=InstallFinder(kAEPrintDocuments, AEHandlePDOC))!=0) return -1;
  209.     
  210.     return kNoError;
  211. }
  212.